package com.smartEdu.service.impl.app;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.smartEdu.commons.CMap;
import com.smartEdu.commons.LogCvt;
import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.dao.ChapterDao;
import com.smartEdu.dao.CourseCategoryDao;
import com.smartEdu.exception.JsonException;
import com.smartEdu.exception.ServiceException;
import com.smartEdu.model.ChapterChildModel;
import com.smartEdu.model.ChapterModel;
import com.smartEdu.model.ChapterTotalModel;
import com.smartEdu.model.CourseCategoryModel;
import com.smartEdu.service.ChapterService;
import com.smartEdu.utils.JsonUtil;

@Service(value="chapterServiceImpl")
public class ChapterServiceImpl extends BaseServiceImpl implements ChapterService{

	@Autowired
	@Qualifier(value="chapterDaoImpl")
    private	ChapterDao chapterDao;
	
	@Override
	public void getChapter(Session sess) {
		// TODO Auto-generated method stub
		List model=new ArrayList<ChapterTotalModel>();
		
		Map<String,Object> jsonmap=null;
		List<ChapterModel> model1=null;
		
		CMap map=null;
		try {
			map=SetToMap(sess);
			String pk="AF3442FSAFD";
			//暂时写死，目录都是获取c语言课程的目录
//			model1=chapterDao.getChapter(map.gets("pk"));
			model1=chapterDao.getChapter(pk);
			for(ChapterModel chapterModel:model1){
				ChapterTotalModel chapterTotalModel=new ChapterTotalModel();
				List<ChapterChildModel> model2=null;
				model2=chapterDao.getChapterChild(chapterModel.getPk().toString());
			    chapterTotalModel.setPk(chapterModel.getPk().toString());
			    chapterTotalModel.setName(chapterModel.getName().toString());
			    chapterTotalModel.setList(model2);
			    model.add(chapterTotalModel);
			}
            sess.put("chapter", model);
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.OK);
		}
		catch (JsonException e){
			LogCvt.error(Tag_Tips.JSONERROR,e);
			throw new ServiceException("json出错");
		}
		catch (Exception e) {
			LogCvt.error(e.getMessage(),e);
			throw new ServiceException("业务流程出错");
		}
		finally {
			map=null;
		}
	}
	
}
